package com.sirun.cn.fca.widget;

import android.content.res.Resources;
import android.graphics.Color;
import android.util.DisplayMetrics;

public class Utils {
    public static float dpToPixel(float dp) {
        DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
        return dp * metrics.density;
    }
    public static int setColor(float val,int mCount) {
        float one = (255 + 255) / (mCount * 2 / 3);
        int r = 0, g = 0, b = 0;
        if (val < (mCount * 1 / 10)) {
            r = 143;
            g = 12;
            b=37;
        } else if (val >= (mCount * 1 / 10) && val < (mCount * 1 / 5)) {
            r = 156;
            g = 12;
            b=38;
        }else if (val >= (mCount * 1 / 5) && val < (mCount * 3 / 10)) {
            r = 175;
            g = 10;
            b=40;
        }else if (val >= (mCount * 3 / 10) && val < (mCount * 2 / 5)) {
            r = 185;
            g = 9;
            b=42;
        }else if (val >= (mCount * 2 / 5) && val < (mCount * 1 / 2)) {
            r = 195;
            g = 9;
            b=42;
        }else if (val >= (mCount * 1 / 2) && val < (mCount * 3 / 5)) {
            r = 205;
            g = 8;
            b=43;
        }else if (val >= (mCount * 3 /5) && val < (mCount * 7 / 10)) {
            r = 218;
            g = 7;
            b=44;
        }else if (val >= (mCount * 7 /10) && val < (mCount * 4 / 5)) {
            r = 228;
            g = 6;
            b=44;
        } else {
            r = 250;
            g=5;
            b=50;
        }
        return Color.rgb(r, g, b);
    }
}
